@model DeathReportManagement.Models.DeathReport
@{
    ViewData["Title"] = "编辑死亡报告";
}

<h2>编辑死亡报告</h2>

<form method="post">
    <div asp-validation-summary="All" class="text-danger"></div>
    
    <div class="alert alert-info">
        <strong>报告编号：</strong>@Model.ReportNo
    </div>
    
    <!-- 基础信息 -->
    <div class="form-section">
        <h5>基础信息</h5>
        <div class="row">
            <div class="col-md-4">
                <label asp-for="OutpatientNo" class="form-label">门诊号</label>
                <input asp-for="OutpatientNo" class="form-control" />
                <span asp-validation-for="OutpatientNo" class="text-danger"></span>
            </div>
            <div class="col-md-4">
                <label asp-for="InpatientNo" class="form-label">住院号</label>
                <input asp-for="InpatientNo" class="form-control" />
                <span asp-validation-for="InpatientNo" class="text-danger"></span>
            </div>
            <div class="col-md-4">
                <label asp-for="HospitalizationCount" class="form-label">住院次数</label>
                <input asp-for="HospitalizationCount" class="form-control" type="number" />
                <span asp-validation-for="HospitalizationCount" class="text-danger"></span>
            </div>
        </div>
    </div>
    
    <!-- 死者信息 -->
    <div class="form-section">
        <h5>死者信息</h5>
        <div class="row">
            <div class="col-md-6">
                <label asp-for="DeceasedName" class="form-label">死者姓名 <span class="required">*</span></label>
                <input asp-for="DeceasedName" class="form-control" required />
                <span asp-validation-for="DeceasedName" class="text-danger"></span>
            </div>
            <div class="col-md-3">
                <label asp-for="IsAnonymous" class="form-label">是否无名氏</label>
                <select asp-for="IsAnonymous" class="form-select">
                    <option value="false">否</option>
                    <option value="true">是</option>
                </select>
            </div>
            <div class="col-md-3">
                <label asp-for="Gender" class="form-label">性别 <span class="required">*</span></label>
                <select asp-for="Gender" class="form-select" required>
                    <option value="">请选择</option>
                    <option value="男">男</option>
                    <option value="女">女</option>
                    <option value="未知的">未知的</option>
                </select>
                <span asp-validation-for="Gender" class="text-danger"></span>
            </div>
        </div>
        
        <div class="row mt-3">
            <div class="col-md-4">
                <label asp-for="Ethnicity" class="form-label">民族 <span class="required">*</span></label>
                <select asp-for="Ethnicity" class="form-select" required>
                    <option value="">请选择</option>
                    @foreach (var ethnicity in ViewBag.Ethnicities as List<DeathReportManagement.Models.Dictionary> ?? new List<DeathReportManagement.Models.Dictionary>())
                    {
                        <option value="@ethnicity.Name" selected="@(ethnicity.Name == Model.Ethnicity)">@ethnicity.Name</option>
                    }
                </select>
                <span asp-validation-for="Ethnicity" class="text-danger"></span>
            </div>
            <div class="col-md-4">
                <label asp-for="IdType" class="form-label">证件类型 <span class="required">*</span></label>
                <select asp-for="IdType" class="form-select" required>
                    <option value="">请选择</option>
                    @foreach (var idType in ViewBag.IdTypes as List<DeathReportManagement.Models.Dictionary>)
                    {
                        <option value="@idType.Name" selected="@(idType.Name == Model.IdType)">@idType.Name</option>
                    }
                </select>
                <span asp-validation-for="IdType" class="text-danger"></span>
            </div>
            <div class="col-md-4">
                <label asp-for="IdNumber" class="form-label">证件号码 <span class="required">*</span></label>
                <input asp-for="IdNumber" class="form-control" required />
                <span asp-validation-for="IdNumber" class="text-danger"></span>
            </div>
        </div>
        
        <div class="row mt-3">
            <div class="col-md-4">
                <label asp-for="BirthDate" class="form-label">出生日期 <span class="required">*</span></label>
                <input asp-for="BirthDate" class="form-control" type="date" required />
                <span asp-validation-for="BirthDate" class="text-danger"></span>
            </div>
            <div class="col-md-4">
                <label asp-for="Age" class="form-label">年龄 <span class="required">*</span></label>
                <input asp-for="Age" class="form-control" type="number" required />
                <span asp-validation-for="Age" class="text-danger"></span>
            </div>
            <div class="col-md-4">
                <label asp-for="AgeUnit" class="form-label">年龄单位 <span class="required">*</span></label>
                <select asp-for="AgeUnit" class="form-select" required>
                    <option value="">请选择</option>
                    <option value="岁">岁</option>
                    <option value="月">月</option>
                    <option value="天">天</option>
                </select>
                <span asp-validation-for="AgeUnit" class="text-danger"></span>
            </div>
        </div>
        
        <div class="row mt-3">
            <div class="col-md-4">
                <label asp-for="MaritalStatus" class="form-label">婚姻状况 <span class="required">*</span></label>
                <select asp-for="MaritalStatus" class="form-select" required>
                    <option value="">请选择</option>
                    @foreach (var status in ViewBag.MaritalStatuses as List<DeathReportManagement.Models.Dictionary>)
                    {
                        <option value="@status.Name" selected="@(status.Name == Model.MaritalStatus)">@status.Name</option>
                    }
                </select>
                <span asp-validation-for="MaritalStatus" class="text-danger"></span>
            </div>
            <div class="col-md-4">
                <label asp-for="Education" class="form-label">文化程度 <span class="required">*</span></label>
                <select asp-for="Education" class="form-select" required>
                    <option value="">请选择</option>
                    @foreach (var education in ViewBag.Educations as List<DeathReportManagement.Models.Dictionary>)
                    {
                        <option value="@education.Name" selected="@(education.Name == Model.Education)">@education.Name</option>
                    }
                </select>
                <span asp-validation-for="Education" class="text-danger"></span>
            </div>
            <div class="col-md-4">
                <label asp-for="PersonalIdentity" class="form-label">个人身份 <span class="required">*</span></label>
                <select asp-for="PersonalIdentity" class="form-select" required>
                    <option value="">请选择</option>
                    @foreach (var identity in ViewBag.PersonalIdentities as List<DeathReportManagement.Models.Dictionary>)
                    {
                        <option value="@identity.Name" selected="@(identity.Name == Model.PersonalIdentity)">@identity.Name</option>
                    }
                </select>
                <span asp-validation-for="PersonalIdentity" class="text-danger"></span>
            </div>
        </div>
    </div>
    
    <!-- 死亡信息 -->
    <div class="form-section">
        <h5>死亡信息</h5>
        <div class="row">
            <div class="col-md-6">
                <label asp-for="DeathDateTime" class="form-label">死亡日期 <span class="required">*</span></label>
                <input asp-for="DeathDateTime" class="form-control" type="datetime-local" required />
                <span asp-validation-for="DeathDateTime" class="text-danger"></span>
            </div>
            <div class="col-md-6">
                <label asp-for="DeathLocation" class="form-label">死亡地点 <span class="required">*</span></label>
                <select asp-for="DeathLocation" class="form-select" required>
                    <option value="">请选择</option>
                    @foreach (var location in ViewBag.DeathLocations as List<DeathReportManagement.Models.Dictionary>)
                    {
                        <option value="@location.Name" selected="@(location.Name == Model.DeathLocation)">@location.Name</option>
                    }
                </select>
                <span asp-validation-for="DeathLocation" class="text-danger"></span>
            </div>
        </div>
        
        <div class="row mt-3">
            <div class="col-md-6">
                <label asp-for="IsPregnant" class="form-label">是否处于妊娠期或妊娠终止后42天内</label>
                <select asp-for="IsPregnant" class="form-select">
                    <option value="false">否</option>
                    <option value="true">是</option>
                </select>
            </div>
            <div class="col-md-6">
                <label asp-for="WorkUnit" class="form-label">生前工作单位 <span class="required">*</span></label>
                <input asp-for="WorkUnit" class="form-control" required />
                <span asp-validation-for="WorkUnit" class="text-danger"></span>
            </div>
        </div>
    </div>
    
    <!-- 地址信息 -->
    <div class="form-section">
        <h5>地址信息</h5>
        <div class="row">
            <div class="col-md-6">
                <label asp-for="HouseholdAddressType" class="form-label">户籍地址类型</label>
                <select asp-for="HouseholdAddressType" class="form-select">
                    @foreach (var type in ViewBag.AddressTypes as List<DeathReportManagement.Models.Dictionary>)
                    {
                        <option value="@type.Name" selected="@(type.Name == Model.HouseholdAddressType)">@type.Name</option>
                    }
                </select>
            </div>
            <div class="col-md-6">
                <label asp-for="HouseholdDetailAddress" class="form-label">户籍详细地址 <span class="required">*</span></label>
                <input asp-for="HouseholdDetailAddress" class="form-control" required />
                <span asp-validation-for="HouseholdDetailAddress" class="text-danger"></span>
            </div>
        </div>
        
        <div class="row mt-3">
            <div class="col-md-6">
                <label asp-for="ResidenceAddressType" class="form-label">常住地址类型 <span class="required">*</span></label>
                <select asp-for="ResidenceAddressType" class="form-select" required>
                    <option value="">请选择</option>
                    @foreach (var type in ViewBag.AddressTypes as List<DeathReportManagement.Models.Dictionary>)
                    {
                        <option value="@type.Name" selected="@(type.Name == Model.ResidenceAddressType)">@type.Name</option>
                    }
                </select>
                <span asp-validation-for="ResidenceAddressType" class="text-danger"></span>
            </div>
            <div class="col-md-6">
                <label asp-for="ResidenceDetailAddress" class="form-label">常住详细地址 <span class="required">*</span></label>
                <input asp-for="ResidenceDetailAddress" class="form-control" required />
                <span asp-validation-for="ResidenceDetailAddress" class="text-danger"></span>
            </div>
        </div>
    </div>
    
    <!-- 联系人信息 -->
    <div class="form-section">
        <h5>联系人信息</h5>
        <div class="row">
            <div class="col-md-4">
                <label asp-for="ContactName" class="form-label">联系人姓名 <span class="required">*</span></label>
                <input asp-for="ContactName" class="form-control" required />
                <span asp-validation-for="ContactName" class="text-danger"></span>
            </div>
            <div class="col-md-4">
                <label asp-for="ContactPhone" class="form-label">联系电话 <span class="required">*</span></label>
                <input asp-for="ContactPhone" class="form-control" required />
                <span asp-validation-for="ContactPhone" class="text-danger"></span>
            </div>
            <div class="col-md-4">
                <label asp-for="ContactIdType" class="form-label">证件类型</label>
                <select asp-for="ContactIdType" class="form-select">
                    @foreach (var idType in ViewBag.IdTypes as List<DeathReportManagement.Models.Dictionary>)
                    {
                        <option value="@idType.Name" selected="@(idType.Name == Model.ContactIdType)">@idType.Name</option>
                    }
                </select>
            </div>
        </div>
    </div>
    
    <!-- 32. 家属住址或工作单位 -->
    <div class="form-section">
        <h5>家属信息</h5>
        <div class="row">
            <div class="col-md-12">
                <label asp-for="FamilyAddressOrWorkUnit" class="form-label">家属住址或工作单位 <span class="required">*</span></label>
                <input asp-for="FamilyAddressOrWorkUnit" class="form-control" required />
                <span asp-validation-for="FamilyAddressOrWorkUnit" class="text-danger"></span>
            </div>
        </div>
    </div>
    
    <!-- 死因分析 -->
    <div class="form-section">
        <h5>死因分析</h5>
        
        <!-- 死因A -->
        <div class="row mb-3">
            <div class="col-md-4">
                <label asp-for="DeathCauseA" class="form-label">直接导致死亡的疾病A <span class="required">*</span></label>
                <input asp-for="DeathCauseA" class="form-control" required />
                <span asp-validation-for="DeathCauseA" class="text-danger"></span>
            </div>
            <div class="col-md-3">
                <label asp-for="DeathCauseAIcd10" class="form-label">疾病A的ICD10编码</label>
                <input asp-for="DeathCauseAIcd10" class="form-control icd10-search" data-target="DeathCauseA" />
                <div class="icd10-suggestions" style="display:none;"></div>
                <span asp-validation-for="DeathCauseAIcd10" class="text-danger"></span>
            </div>
            <div class="col-md-3">
                <label asp-for="DeathCauseAInterval" class="form-label">A疾病发病至死亡的时间间隔</label>
                <input asp-for="DeathCauseAInterval" type="number" step="0.1" min="0" max="999.9" class="form-control" />
                <span asp-validation-for="DeathCauseAInterval" class="text-danger"></span>
            </div>
            <div class="col-md-2">
                <label asp-for="DeathCauseAIntervalUnit" class="form-label">间隔时间单位A</label>
                <select asp-for="DeathCauseAIntervalUnit" class="form-select">
                    <option value="">请选择</option>
                    @foreach (var unit in ViewBag.IntervalUnits as List<DeathReportManagement.Models.Dictionary> ?? new List<DeathReportManagement.Models.Dictionary>())
                    {
                        <option value="@unit.Name" selected="@(unit.Name == Model.DeathCauseAIntervalUnit)">@unit.Name</option>
                    }
                </select>
            </div>
        </div>
        
        <!-- 死因B -->
        <div class="row mb-3">
            <div class="col-md-4">
                <label asp-for="DeathCauseB" class="form-label">直接导致死亡的疾病B</label>
                <input asp-for="DeathCauseB" class="form-control" />
                <span asp-validation-for="DeathCauseB" class="text-danger"></span>
            </div>
            <div class="col-md-3">
                <label asp-for="DeathCauseBIcd10" class="form-label">疾病B的ICD10编码</label>
                <input asp-for="DeathCauseBIcd10" class="form-control icd10-search" data-target="DeathCauseB" />
                <div class="icd10-suggestions" style="display:none;"></div>
                <span asp-validation-for="DeathCauseBIcd10" class="text-danger"></span>
            </div>
            <div class="col-md-3">
                <label asp-for="DeathCauseBInterval" class="form-label">B疾病发病至死亡的时间间隔</label>
                <input asp-for="DeathCauseBInterval" type="number" step="0.1" min="0" max="999.9" class="form-control" />
                <span asp-validation-for="DeathCauseBInterval" class="text-danger"></span>
            </div>
            <div class="col-md-2">
                <label asp-for="DeathCauseBIntervalUnit" class="form-label">间隔时间单位B</label>
                <select asp-for="DeathCauseBIntervalUnit" class="form-select">
                    <option value="">请选择</option>
                    @foreach (var unit in ViewBag.IntervalUnits as List<DeathReportManagement.Models.Dictionary> ?? new List<DeathReportManagement.Models.Dictionary>())
                    {
                        <option value="@unit.Name" selected="@(unit.Name == Model.DeathCauseBIntervalUnit)">@unit.Name</option>
                    }
                </select>
            </div>
        </div>
        
        <!-- 死因C -->
        <div class="row mb-3">
            <div class="col-md-4">
                <label asp-for="DeathCauseC" class="form-label">直接导致死亡的疾病C</label>
                <input asp-for="DeathCauseC" class="form-control" />
                <span asp-validation-for="DeathCauseC" class="text-danger"></span>
            </div>
            <div class="col-md-3">
                <label asp-for="DeathCauseCIcd10" class="form-label">疾病C的ICD10编码</label>
                <input asp-for="DeathCauseCIcd10" class="form-control icd10-search" data-target="DeathCauseC" />
                <div class="icd10-suggestions" style="display:none;"></div>
                <span asp-validation-for="DeathCauseCIcd10" class="text-danger"></span>
            </div>
            <div class="col-md-3">
                <label asp-for="DeathCauseCInterval" class="form-label">C疾病发病至死亡的时间间隔</label>
                <input asp-for="DeathCauseCInterval" type="number" step="0.1" min="0" max="999.9" class="form-control" />
                <span asp-validation-for="DeathCauseCInterval" class="text-danger"></span>
            </div>
            <div class="col-md-2">
                <label asp-for="DeathCauseCIntervalUnit" class="form-label">间隔时间单位C</label>
                <select asp-for="DeathCauseCIntervalUnit" class="form-select">
                    <option value="">请选择</option>
                    @foreach (var unit in ViewBag.IntervalUnits as List<DeathReportManagement.Models.Dictionary> ?? new List<DeathReportManagement.Models.Dictionary>())
                    {
                        <option value="@unit.Name" selected="@(unit.Name == Model.DeathCauseCIntervalUnit)">@unit.Name</option>
                    }
                </select>
            </div>
        </div>
        
        <!-- 死因D -->
        <div class="row mb-3">
            <div class="col-md-4">
                <label asp-for="DeathCauseD" class="form-label">直接导致死亡的疾病D</label>
                <input asp-for="DeathCauseD" class="form-control" />
                <span asp-validation-for="DeathCauseD" class="text-danger"></span>
            </div>
            <div class="col-md-3">
                <label asp-for="DeathCauseDIcd10" class="form-label">疾病D的ICD10编码</label>
                <input asp-for="DeathCauseDIcd10" class="form-control icd10-search" data-target="DeathCauseD" />
                <div class="icd10-suggestions" style="display:none;"></div>
                <span asp-validation-for="DeathCauseDIcd10" class="text-danger"></span>
            </div>
            <div class="col-md-3">
                <label asp-for="DeathCauseDInterval" class="form-label">D疾病发病至死亡的时间间隔</label>
                <input asp-for="DeathCauseDInterval" type="number" step="0.1" min="0" max="999.9" class="form-control" />
                <span asp-validation-for="DeathCauseDInterval" class="text-danger"></span>
            </div>
            <div class="col-md-2">
                <label asp-for="DeathCauseDIntervalUnit" class="form-label">间隔时间单位D</label>
                <select asp-for="DeathCauseDIntervalUnit" class="form-select">
                    <option value="">请选择</option>
                    @foreach (var unit in ViewBag.IntervalUnits as List<DeathReportManagement.Models.Dictionary> ?? new List<DeathReportManagement.Models.Dictionary>())
                    {
                        <option value="@unit.Name" selected="@(unit.Name == Model.DeathCauseDIntervalUnit)">@unit.Name</option>
                    }
                </select>
            </div>
        </div>
        
        <!-- 其他疾病原因和根本死亡原因 -->
        <div class="row mb-3">
            <div class="col-md-4">
                <label asp-for="OtherCause" class="form-label">其他疾病原因</label>
                <input asp-for="OtherCause" class="form-control" />
                <span asp-validation-for="OtherCause" class="text-danger"></span>
            </div>
            <div class="col-md-3">
                <label asp-for="OtherCauseIcd10" class="form-label">其他病因ICD10编码</label>
                <input asp-for="OtherCauseIcd10" class="form-control icd10-search" data-target="OtherCause" />
                <div class="icd10-suggestions" style="display:none;"></div>
                <span asp-validation-for="OtherCauseIcd10" class="text-danger"></span>
            </div>
        </div>
        
        <div class="row mb-3">
            <div class="col-md-4">
                <label asp-for="UnderlyingCause" class="form-label">根本死亡原因描述</label>
                <input asp-for="UnderlyingCause" class="form-control" />
                <span asp-validation-for="UnderlyingCause" class="text-danger"></span>
            </div>
            <div class="col-md-3">
                <label asp-for="UnderlyingCauseIcd10" class="form-label">根本死亡原因ICD10编码</label>
                <input asp-for="UnderlyingCauseIcd10" class="form-control icd10-search" data-target="UnderlyingCause" />
                <div class="icd10-suggestions" style="display:none;"></div>
                <span asp-validation-for="UnderlyingCauseIcd10" class="text-danger"></span>
            </div>
        </div>
    </div>
    
    <!-- 诊断信息 -->
    <div class="form-section">
        <h5>诊断信息</h5>
        <div class="row">
            <div class="col-md-4">
                <label asp-for="HighestDiagnosisUnit" class="form-label">最高诊断单位</label>
                <select asp-for="HighestDiagnosisUnit" class="form-select">
                    <option value="">请选择</option>
                    @foreach (var unit in ViewBag.HighestDiagnosisUnits as List<DeathReportManagement.Models.Dictionary> ?? new List<DeathReportManagement.Models.Dictionary>())
                    {
                        <option value="@unit.Name" selected="@(unit.Name == Model.HighestDiagnosisUnit)">@unit.Name</option>
                    }
                </select>
            </div>
            <div class="col-md-4">
                <label asp-for="HighestDiagnosisBasis" class="form-label">最高诊断依据</label>
                <select asp-for="HighestDiagnosisBasis" class="form-select" id="HighestDiagnosisBasis">
                    <option value="">请选择</option>
                    @foreach (var basis in ViewBag.HighestDiagnosisBases as List<DeathReportManagement.Models.Dictionary> ?? new List<DeathReportManagement.Models.Dictionary>())
                    {
                        <option value="@basis.Name" selected="@(basis.Name == Model.HighestDiagnosisBasis)">@basis.Name</option>
                    }
                </select>
            </div>
        </div>
    </div>
    
    <!-- 填卡医生信息 -->
    <div class="form-section">
        <h5>医生信息</h5>
        <div class="row">
            <div class="col-md-4">
                <label asp-for="FillingDoctor" class="form-label">填卡医生 <span class="required">*</span></label>
                <input asp-for="FillingDoctor" class="form-control" required />
                <span asp-validation-for="FillingDoctor" class="text-danger"></span>
            </div>
            <div class="col-md-4">
                <label asp-for="FillingDate" class="form-label">医生填卡日期</label>
                <input asp-for="FillingDate" type="date" class="form-control" />
                <span asp-validation-for="FillingDate" class="text-danger"></span>
            </div>
        </div>
    </div>
    
    <!-- 审核和签名信息 -->
    <div class="form-section">
        <h5>审核和签名</h5>
        <div class="row">
            <div class="col-md-3">
                <label asp-for="AuditorName" class="form-label">审核人</label>
                <input asp-for="AuditorName" class="form-control" />
                <span asp-validation-for="AuditorName" class="text-danger"></span>
            </div>
            <div class="col-md-3">
                <label asp-for="PoliceSignature" class="form-label">民警签名</label>
                <input asp-for="PoliceSignature" class="form-control" />
                <span asp-validation-for="PoliceSignature" class="text-danger"></span>
            </div>
            <div class="col-md-6">
                <label asp-for="Remarks" class="form-label">备注（最多40个字符）</label>
                <input asp-for="Remarks" class="form-control" maxlength="40" />
                <span asp-validation-for="Remarks" class="text-danger"></span>
            </div>
        </div>
    </div>
    
    <!-- 病史和症状体征 -->
    <div class="form-section">
        <h5>病史信息</h5>
        <div class="row">
            <div class="col-md-12">
                <label asp-for="MedicalHistoryAndSymptoms" class="form-label">死者生前病史及症状体征（最多800个字符）</label>
                <textarea asp-for="MedicalHistoryAndSymptoms" class="form-control" rows="4" maxlength="800" id="MedicalHistoryAndSymptoms"></textarea>
                <span asp-validation-for="MedicalHistoryAndSymptoms" class="text-danger"></span>
                <small class="text-muted">如果最高诊断依据是"死后推断"，则此项为必填</small>
            </div>
        </div>
    </div>
    
    <!-- 调查信息 -->
    <div class="form-section">
        <h5>调查信息</h5>
        <div class="row mb-3">
            <div class="col-md-3">
                <label asp-for="IntervieweeName" class="form-label">被调查者姓名（最多20个字符）</label>
                <input asp-for="IntervieweeName" class="form-control" maxlength="20" />
                <span asp-validation-for="IntervieweeName" class="text-danger"></span>
            </div>
            <div class="col-md-3">
                <label asp-for="RelationshipToDeceased" class="form-label">与死者关系（最多10个字符）</label>
                <input asp-for="RelationshipToDeceased" class="form-control" maxlength="10" />
                <span asp-validation-for="RelationshipToDeceased" class="text-danger"></span>
            </div>
            <div class="col-md-6">
                <label asp-for="IntervieweeAddress" class="form-label">联系地址或工作单位（最多100个字符）</label>
                <input asp-for="IntervieweeAddress" class="form-control" maxlength="100" />
                <span asp-validation-for="IntervieweeAddress" class="text-danger"></span>
            </div>
        </div>
        
        <div class="row mb-3">
            <div class="col-md-3">
                <label asp-for="IntervieweePhone" class="form-label">被调查者电话号码（最多18个字符）</label>
                <input asp-for="IntervieweePhone" class="form-control" maxlength="18" />
                <span asp-validation-for="IntervieweePhone" class="text-danger"></span>
            </div>
            <div class="col-md-4">
                <label asp-for="CauseInference" class="form-label">死因推断（最多60个字符）</label>
                <input asp-for="CauseInference" class="form-control" maxlength="60" />
                <span asp-validation-for="CauseInference" class="text-danger"></span>
            </div>
            <div class="col-md-3">
                <label asp-for="InvestigatorSignature" class="form-label">调查者签名（最多20个字符）</label>
                <input asp-for="InvestigatorSignature" class="form-control" maxlength="20" />
                <span asp-validation-for="InvestigatorSignature" class="text-danger"></span>
            </div>
            <div class="col-md-2">
                <label asp-for="InvestigationDate" class="form-label">调查日期</label>
                <input asp-for="InvestigationDate" type="date" class="form-control" />
                <span asp-validation-for="InvestigationDate" class="text-danger"></span>
            </div>
        </div>
    </div>
    
    <!-- 审核日期和错误内容 -->
    <div class="form-section">
        <h5>审核信息</h5>
        <div class="row">
            <div class="col-md-3">
                <label asp-for="AuditDate" class="form-label">审核日期</label>
                <input asp-for="AuditDate" type="date" class="form-control" />
                <span asp-validation-for="AuditDate" class="text-danger"></span>
            </div>
            <div class="col-md-9">
                <label asp-for="ErrorContent" class="form-label">错误内容（最多300个字符）</label>
                <textarea asp-for="ErrorContent" class="form-control" rows="3" maxlength="300"></textarea>
                <span asp-validation-for="ErrorContent" class="text-danger"></span>
                <small class="text-muted">当用户是审核人时，此项内容被填写时，需要给用户以错卡提醒在列表中变红提示</small>
            </div>
        </div>
    </div>
    
    <div class="btn-group-custom">
        <button type="submit" class="btn btn-primary">保存修改</button>
        <a asp-action="Details" asp-route-id="@Model.Id" class="btn btn-secondary">取消</a>
    </div>
</form>

@section Scripts {
    <script>
        // 性别联动妊娠期选项
        $('#Gender').change(function() {
            var gender = $(this).val();
            var pregnantSelect = $('#IsPregnant');
            if (gender !== '女') {
                pregnantSelect.val('false').prop('disabled', true);
            } else {
                pregnantSelect.prop('disabled', false);
            }
        });
        
        // 户籍地址联动常住地址
        $('#HouseholdAddressType, #HouseholdDetailAddress').change(function() {
            var householdType = $('#HouseholdAddressType').val();
            var householdDetail = $('#HouseholdDetailAddress').val();
            
            $('#ResidenceAddressType').val(householdType);
            $('#ResidenceDetailAddress').val(householdDetail);
        });
        
        // 身份证号自动计算年龄和出生日期
        $('#IdNumber').blur(function() {
            var idNumber = $(this).val();
            if (idNumber.length === 18) {
                var year = idNumber.substring(6, 10);
                var month = idNumber.substring(10, 12);
                var day = idNumber.substring(12, 14);
                
                var birthDate = year + '-' + month + '-' + day;
                $('#BirthDate').val(birthDate);
                
                var today = new Date();
                var birth = new Date(birthDate);
                var age = today.getFullYear() - birth.getFullYear();
                var monthDiff = today.getMonth() - birth.getMonth();
                
                if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birth.getDate())) {
                    age--;
                }
                
                $('#Age').val(age);
                $('#AgeUnit').val('岁');
            }
        });
        
        // 初始化
        $(document).ready(function() {
            $('#Gender').trigger('change');
        });

        // 最高诊断依据联动病史必填
        $('#HighestDiagnosisBasis').change(function() {
            var basis = $(this).val();
            var historyTextarea = $('#MedicalHistoryAndSymptoms');
            if (basis === '死后推断') {
                historyTextarea.prop('required', true);
                historyTextarea.closest('div').find('label').html('死者生前病史及症状体征（最多800个字符） <span class="required">*</span>');
            } else {
                historyTextarea.prop('required', false);
                historyTextarea.closest('div').find('label').html('死者生前病史及症状体征（最多800个字符）');
            }
        });

        // ICD10编码搜索功能
        $('.icd10-search').on('input', function() {
            var $input = $(this);
            var keyword = $input.val();
            var targetField = $input.data('target');
            var $suggestions = $input.siblings('.icd10-suggestions');

            if (keyword.length >= 2) {
                $.ajax({
                    url: '/api/icd10/search',
                    method: 'GET',
                    data: { keyword: keyword },
                    success: function(data) {
                        var html = '';
                        if (data && data.length > 0) {
                            html = '<ul class="list-group position-absolute w-100" style="z-index: 1000; max-height: 200px; overflow-y: auto;">';
                            data.forEach(function(item) {
                                html += '<li class="list-group-item list-group-item-action icd10-item" data-code="' + item.code + '" data-name="' + item.name + '" data-target="' + targetField + '">';
                                html += '<small class="text-muted">' + item.code + '</small><br>' + item.name;
                                html += '</li>';
                            });
                            html += '</ul>';
                        }
                        $suggestions.html(html).show();
                    },
                    error: function() {
                        $suggestions.hide();
                    }
                });
            } else {
                $suggestions.hide();
            }
        });

        // 选择ICD10编码
        $(document).on('click', '.icd10-item', function() {
            var $item = $(this);
            var code = $item.data('code');
            var name = $item.data('name');
            var targetField = $item.data('target');

            // 设置ICD10编码
            $item.closest('.row').find('[name$="' + targetField + 'Icd10"]').val(code);
            
            // 设置疾病名称
            $item.closest('.row').find('[name$="' + targetField + '"]').val(name);

            // 隐藏建议列表
            $('.icd10-suggestions').hide();

            // 设置对应的时间间隔为必填（如果ICD10编码不为空）
            var intervalField = $item.closest('.row').find('[name$="' + targetField + 'Interval"]');
            var unitField = $item.closest('.row').find('[name$="' + targetField + 'IntervalUnit"]');
            if (code) {
                intervalField.prop('required', true);
                unitField.prop('required', true);
            }
        });

        // 点击其他地方隐藏建议列表
        $(document).click(function(e) {
            if (!$(e.target).hasClass('icd10-search')) {
                $('.icd10-suggestions').hide();
            }
        });

        // 表单提交前验证
        $('form').submit(function(e) {
            var isValid = true;

            // 检查ICD10选择后的时间间隔验证
            $('[name$="Icd10"]').each(function() {
                var $icdInput = $(this);
                if ($icdInput.val()) {
                    var fieldName = $icdInput.attr('name').replace('Icd10', '');
                    var $intervalInput = $('[name="' + fieldName + 'Interval"]');
                    var $unitSelect = $('[name="' + fieldName + 'IntervalUnit"]');

                    if ($intervalInput.length && !$intervalInput.val()) {
                        alert('选择ICD10编码后，时间间隔为必填项');
                        $intervalInput.focus();
                        isValid = false;
                        return false;
                    }

                    if ($intervalInput.length && $intervalInput.val() && $unitSelect.length && !$unitSelect.val()) {
                        alert('填写时间间隔后，时间单位为必填项');
                        $unitSelect.focus();
                        isValid = false;
                        return false;
                    }
                }
            });

            return isValid;
        });
    </script>
}